package com.hspedu.list_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * List三种遍历方式
 * 1.使用iterator
 *      Iterator iter = col.iterator();
 *      while(iter.hasNext()){
 *          Object o = iter.next();
 *      }
 * 2.使用增强for
 *      for(Object o:col){
 *          System.out.println(o);
 *      }
 * 3.使用普通for
 *      for(int i = 0; i < list.size(); i++){
 *          Object object = list.get(i);
 *          System.out.println(object);
 *      }
 * @author enomix
 * @date 2022-06-16 11:43
 */
public class ListFor {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("jack");
        list.add("tom");
        list.add("鱼香肉丝");
        list.add("北京烤鸭");

        //迭代器
        System.out.println("===迭代器iterator===");
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object obj = iterator.next();
            System.out.println(obj);
        }


        //增强for
        System.out.println("===增强for===");
        for (Object o : list) {
            System.out.println("o = " + o);
        }


        System.out.println("===普通for===");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
